package qlsl.androiddesign.adapter.subadapter;

import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.TextView;
import qlsl.androiddesign.activity.baseactivity.BaseActivity;
import qlsl.androiddesign.adapter.baseadapter.BaseAdapter;
import qlsl.androiddesign.entity.otherentity.CarBrand;

/**
 * 二手车品牌适配器<br/>
 */
public class CarBrandAdapter extends BaseAdapter<CarBrand> {

	private GridView gridView;

	private int selectPosition;

	public CarBrandAdapter(BaseActivity activity, List<CarBrand> list, GridView gridView) {
		super(activity, list);
		this.gridView = gridView;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		convertView = getItemView(convertView, R.layout.griditem_car_brand);

		TextView tv_text = getView(convertView, R.id.tv_text);

		CarBrand item = getItem(position);
		String name = item.getName();

		tv_text.setText(name);
		if (selectPosition == position) {
			tv_text.setActivated(true);
		} else {
			tv_text.setActivated(false);
		}

		tv_text.setOnClickListener(new View.OnClickListener() {

			public void onClick(View view) {
				selectPosition = position;
				gridView.invalidateViews();
			}
		});

		return convertView;
	}

	public int getSelectPosition() {
		return selectPosition;
	}
}
